package zhangtao.bwie.com.yuekao2;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.facebook.drawee.backends.pipeline.Fresco;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import Bean.ShopDataBean;
import Presenter.IPresenter;
import Views.IView;

/**
 * Created by ZhangTAO on 2017/12/21.
 */

public class ShopData extends AppCompatActivity implements IView{

    private RecyclerView recys;
    private IPresenter iPresenter;
    private List<ShopDataBean.DataBean> data;
    private HashMap<String, String> map;
    private MyAdapters myAdapters;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shopdata);
        Fresco.initialize(this);
        recys = (RecyclerView) findViewById(R.id.recys);
        map = new HashMap<>();
        map.put("pscid","39");
        map.put("page","1");
        setPresenter("https://www.zhaoapi.cn/",map);
    }
    public void setPresenter(String url, Map<String,String> map) {
        iPresenter = new IPresenter();
        iPresenter.attach(this);
        iPresenter.getData(url,map);
    }
    public void setMyadapter() {
        myAdapters = new MyAdapters(this,data);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        recys.setLayoutManager(manager);
        recys.setAdapter(myAdapters);
        myAdapters.setOnItemCheck(new MyAdapters.onitemclick() {
            @Override
            public void setOnItem(View v, int pos) {
                Intent intent = new Intent(ShopData.this,Xiang_act.class);
                int pid = data.get(pos).getPid();
                intent.putExtra("pid",data.get(pos).getPid());
                Log.d("zzz",pid+"");
                startActivity(intent);
            }
        });
    }
    @Override
    public void onSuccess(Object o) {
        if(o instanceof ShopDataBean) {
           ShopDataBean bean = (ShopDataBean) o;
            if(bean != null) {
                data = bean.getData();
                setMyadapter();
            }
        }
    }

    @Override
    public void onFailed(Exception e) {

    }
}
